{extend name="public/nav"}

{block name="main"}
<div class="admin-content">

    <div class="am-cf am-padding">
      <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">相册管理</strong> / <small>Album management</small></div>
    </div>

    <div class="am-g">
      <div class="am-u-md-6 am-cf">
        <div class="am-fl am-cf">
          <div class="am-btn-toolbar am-fl">
              <div class="am-btn-group am-btn-group-xs">
                <button type="button" class="am-btn am-btn-default" onclick='location.href="{:U('album/create')}"'><span class="am-icon-plus"></span> 新增</button>

            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="am-g">
      <div class="am-u-sm-12">
        <form class="am-form">
          <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
              <tr>
                <th class="table-id">ID</th>
                <th class="table-type">相册名称</th>
                <th class="table-title">状态</th>
                <th class="table-title">排序</th>
                <th class="table-title">图片数量</th>
                <th class="table-date">修改日期</th>
                <th class="table-set">操作</th>
              </tr>
          </thead>
          <tbody>
            {foreach $list as $value}
            <tr>
              <td>{$value.id}</td>
              <td><a href="#">{$value.aname}</a></td>
              <td>{$value['status'] == 1 ? '公开':'<span style="color:red">不公开</span>'}</td>
              <td><input type="text" value="{$value.sort}" style="width:40px;" sid="{$value.id}" readonly="readonly" class="setsort"></td>
              <td>{$value.number}</td>
              <td>{:date('Y年m月d日 H:i:s',$value['update_time'])}</td>
              <td>
                <div class="am-btn-toolbar">
                  <div class="am-btn-group am-btn-group-xs">
                    <button type="button" class="am-btn am-btn-default" onclick='location.href="{:U('album/update',['aid'=>$value['id']])}"'><span class="am-icon-pencil-square-o"></span> 编辑</button>
                    <button type="button" class="am-btn am-btn-default" onclick='delSort({$value.id})'><span class="am-icon-trash-o"></span> 删除</button>
                  </div>
                </div>
              </td>
            </tr>
            {/foreach}




          </tbody>
        </table>
          {$page}
          <hr />
          <p>注：.....</p>
        </form>
      </div>

    </div>
  </div>
{/block}

{block name="js"}
    <script type="text/javascript">
        function delSort(sid){
            layer.confirm('是否确定删除该相册下的所有图片？', {
                btn: ['删除','取消'], //按钮
                icon: 0
            }, function(){
                var index = layer.load(2);
                $.post("{:U('album/delete')}",{sid:sid},function(data){
                    layer.close(index);
                    if(data == 1){
                        layer.alert('删除成功！',{
                            icon:1,
                        },function(){
                            location.reload();
                        });
                    }else{
                        layer.alert(data,{
                            icon:2,
                        });
                    }
                });
            });
        }

        layer.config({
            extend: 'extend/layer.ext.js'
        });

        $('.setsort').on('click',function(){
            var sid = $(this).attr('sid');
            layer.prompt({
                title: '输入排序（大的靠前）',
                formType: 0, //prompt风格，支持0-2
            }, function(sort){
                var index = layer.load(2);
                $.post("{:U('album/setsort')}",{aid:sid,sort:sort,update_time:{:time()}},function(data){
                    layer.close(index);
                    if(data == 1){
                        layer.alert('更新成功',{
                            icon:1,
                        },function(){
                            location.reload();
                        });
                    }else{
                        layer.alert(data,{
                            icon:2,
                        });
                    }
                });
            });
        });
    </script>
{/block}
